import 'package:wu_you/data/repository/mall_repository.dart';
import 'package:wu_you/model/home/mall_model.dart';
import 'package:wu_you/model/mall/mall_model.dart';
import 'package:wu_you/model/mall/order_model.dart';

import 'http_bloc.dart';

///商圈分类类目
class MallsCategoryBloc extends HttpBloc<List<MallCategoryModel>> {
  @override
  Future<List<MallCategoryModel>> obtainData(HttpEvent event) {
    if (event is IdsHttpEvent) {
      return MallRepository.category(id: event.id);
    }
    return MallRepository.category();
  }
}




///商品分组列表事件
class GroupProductEvent extends PageSizeHttpEvent {
  final String nationality_id;
  final String category_id;
  final String goods_type;
  GroupProductEvent({this.nationality_id,this.category_id,this.goods_type,int page, int size = 10}) : super(page, size);
  @override
  List<Object> get props => [nationality_id,category_id,goods_type,page, size];
}

///商品分组列表
class GroupProductBloc extends HttpBloc<List<MallProductModel>> {
  @override
  Future<List<MallProductModel>> obtainData(HttpEvent event) {
    if (event is GroupProductEvent) {
      return MallRepository.getGroupProduct(nationality_id: event.nationality_id,category_id: event.category_id,page: event.page,limit: event.size,goods_type: event.goods_type);
    }
    return Future.error("参数错误");
  }
}


///商品详情
class NewProductDetailBloc extends HttpBloc<GoodsDetail> {
  @override
  Future<GoodsDetail> obtainData(HttpEvent event) {
    if (event is IdHttpEvent) {
      return MallRepository.getNewProductDetail(event.id);
    }
    return Future.error("参数错误");
  }
}


///商城订单模块
class MallOrderListBloc extends HttpBloc<List<OrderListModel>> {
  @override
  Future<List<OrderListModel>> obtainData(HttpEvent event) {
    if (event is MallOrderListEvent) {
      return MallRepository.getOrderList(state: event.state, page: event.page, size: event.size);
    }
    return MallRepository.getOrderList();
  }
}
///商城订单事件
class MallOrderListEvent extends PageSizeHttpEvent {
  final String state;

  MallOrderListEvent(this.state, int page, {int size = 10}) : super(page, size);

  @override
  List<Object> get props => [state, page, size];
}


///订单详情
class OrderDetailBloc extends HttpBloc<OrderListModel> {
  @override
  Future<OrderListModel> obtainData(HttpEvent event) {
    if (event is IdStrHttpEvent) {
      return MallRepository.getOrderDetail(event.id);
    }
    return Future.error("参数错误");
  }
}